﻿using System;

namespace Pisces
{
    /**
     * 对象容器模块,单例
     * created by wangqiang
    **/
    public class EntityContainerModule : AbstractSingletonModule<EntityContainerModule>, InterfaceEntityLiftcycle
    {
        /**
         * 逻辑对象的容器
         */
        private LogicEntityContainer logicEntityContainer;

        /**
         * 创建逻辑对象的工厂方法
         */
        private Func<int, AbstractLogicEntity> createFactory;

        public EntityContainerModule()
        {
            createFactory = DefaultLogicEntityFactory.create;
        }
        
        /**
         * 构造方法
         * 传入创建对象的工厂方法
         */
        public EntityContainerModule(Func<int, AbstractLogicEntity> func)
        { 
           this.createFactory = func;
        }

        public Func<int, AbstractLogicEntity> CreateFactory
        { 
         set => createFactory = value;
        }

        /**
         * 创建对象
         */
        public AbstractLogicEntity createEntity(int type)
        {
           AbstractLogicEntity logicEntity = createFactory(type);

           if (logicEntity == null)
           {
              return logicEntity;
           }
           
           logicEntity.InstanceID = GUIDGenerator.generate();
         
           return logicEntity;
        }

        public override void onInit()
        {
        }

        public override void onAwake()
        {
        }

        public override void onUpdate(float deltaTime)
        {
        }

        public override void onDestroy()
        {
        }
    }
}